package cn.tedu.clyback.menu.service.impl;


import cn.tedu.clyback.menu.mapper.MenuMapper;
import cn.tedu.clyback.menu.pojo.dto.MenuSaveParam;
import cn.tedu.clyback.menu.pojo.dto.MenuSelectParam;
import cn.tedu.clyback.menu.pojo.entity.Menu;
import cn.tedu.clyback.menu.pojo.vo.MenuVO;
import cn.tedu.clyback.menu.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    MenuMapper menuMapper;


    @Override
    public List<MenuVO> selectMenu(MenuSelectParam menuSelectParam) {
        log.debug("开始处理【查询菜单】的业务，参数：{}", menuSelectParam);
        List<MenuVO> menuVOList = menuMapper.selectMenu(menuSelectParam);
        return menuVOList;
    }

    @Override
    public void deleteMenu(Integer menuId) {
        menuMapper.deleteMenu(menuId);
    }

    @Override
    public void saveMenu(MenuSaveParam menuSaveParam) {
        log.debug("开始处理【保存菜单】的业务，参数：{}", menuSaveParam);
        Menu menu = new Menu();
        BeanUtils.copyProperties(menuSaveParam, menu);
        if (menu.getMenuId() == null){
            menuMapper.insert(menuSaveParam);
        }else {
            menuMapper.update(menu);
        }

    }
}